﻿using ADManage.api.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web.Http;
using XF.Meeting.Api.Models;
using XF.Meeting.Entity.CommonEntity;
using XF.Meeting.Entity.Query;
using XF.Meeting.Entity.View;

namespace XF.Meeting.Api.Controllers
{
    public class ReportController : BaseController
    {

        /// <summary>
        /// 获取会议室统计报表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetingRoomReport([FromBody]ObjBase<ReportQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateReportInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetMeetingRoomReport(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MeetingRoomReport>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingRoomReport>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室统计报表失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 获取人员统计报表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetPersonMeetingReport([FromBody]ObjBase<ReportQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateReportInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetPersonMeetingReport(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<PersonMeetingReport>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<PersonMeetingReport>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取人员统计报表失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 获取部门统计报表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetDeptMeetingReport([FromBody]ObjBase<ReportQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateReportInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetDeptMeetingReport(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<DeptMeetingReport>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<DeptMeetingReport>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取部门统计报表失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 获取部门人员统计报表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetDeptPersonMeetingReport([FromBody]ObjBase<ReportQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateReportInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetDeptPersonMeetingReport(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<DeptPersonMeetingReport>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<DeptPersonMeetingReport>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取部门人员统计报表失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 获取人员统计详情报表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetPersonMeetingDetailsReport([FromBody]ObjBase<ReportQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateReportInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetPersonMeetingDetailsReport(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<PersonMeetingDetailsReport>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<PersonMeetingDetailsReport>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取人员统计详情报表失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
    }
}